﻿
CREATE PROCEDURE sec__NameSpaces_Build
AS

DECLARE cur CURSOR READ_ONLY FOR SELECT NameSpace FROM t_NameSpace

DECLARE @NameSpace nvarchar(446)

OPEN cur

FETCH NEXT FROM cur INTO @NameSpace

BEGIN TRAN
DELETE t_NameSpaces

WHILE @@fetch_status = 0 BEGIN

INSERT INTO t_NameSpaces
SELECT (SELECT ID FROM t_NameSpace WHERE NameSpace=@NameSpace), ns.ID FROM t_NameSpace ns
INNER JOIN NameSpaces(@NameSpace) nss ON ns.NameSpace = nss.NameSpace

IF @@ERROR <> 0 RETURN

FETCH NEXT FROM cur INTO @NameSpace

END

COMMIT TRAN

CLOSE cur
DEALLOCATE cur

